//
//  RankTableViewCell.m
//  Cartoon
//
//  Created by dllo on 15/10/29.
//  Copyright © 2015年 YSZ. All rights reserved.
//

#import "RankTableViewCell.h"
#import "Rank.h"
@implementation RankTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{

    self = [super initWithStyle:style reuseIdentifier:
            reuseIdentifier];
    if(self){
    
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = [UIColor colorWithRed:13 / 255.0 green:184 / 255.0 blue: 240 / 255.0 alpha:1];
        [self.contentView addSubview:_titleLabel];
        
        _typeLabel = [[UILabel alloc] init];
        _typeLabel.textColor = [UIColor lightGrayColor];
        _typeLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:_typeLabel];
        
        _lastupLabel = [[UILabel alloc] init];
        _lastupLabel.textColor = [UIColor lightGrayColor];
        _lastupLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:_lastupLabel];
        
        _photoImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_photoImageView];
        _starView = [[StarView alloc] init];
        [self.contentView addSubview:_starView];
        
        _grade_aveLabel = [[UILabel alloc] init];
        _grade_aveLabel.textColor = [UIColor lightGrayColor];
        _grade_aveLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:_grade_aveLabel];
    
    }

    return self;
}

+ (instancetype)rankCellWithTableView:(UITableView *)tableView
{

    RankTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Rank_cell"];

    return cell;
}

- (void)setRankModel:(Rank *)rankModel
{

    _rankModel = rankModel;
    _titleLabel.text = rankModel.title;
    _typeLabel.text = rankModel.type;
    _lastupLabel.text = [NSString stringWithFormat:@"更新至%@",rankModel.lastup];
    [_photoImageView sd_setImageWithURL:[NSURL URLWithString:rankModel.cover_url]placeholderImage:[UIImage imageNamed:@"5"]];
    self.starView.starNum = [rankModel.grade integerValue];
    self.grade_aveLabel.text = [NSString stringWithFormat:@"评分: %@",rankModel.grade_ave];

}


//自定义分割线
- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
    CGContextFillRect(context, rect);
    
    //下分割线
    CGContextSetStrokeColorWithColor(context, [UIColor colorWithRed:52/225. green:143/225. blue:110/225. alpha:1.].CGColor);
    CGContextStrokeRect(context, CGRectMake(100, rect.size.height, rect.size.width - 20, 1));
}


- (void)layoutSubviews
{

    [super layoutSubviews];
    _photoImageView.frame = CGRectMake(5, 5, 80, 100);
    _titleLabel.frame = CGRectMake(100, 10, 200, 20);
    _typeLabel.frame = CGRectMake(100, 35, 200, 20);
    _lastupLabel.frame = CGRectMake(100, 60, 200, 20);
    _starView.frame = CGRectMake(100, 85, 100, 20);
    _grade_aveLabel.frame = CGRectMake(220, 85, 80, 20);
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
